//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.king.platform.utils;

import cn.hutool.core.date.DateUtil;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class MyDateUtil extends DateUtil {
  public static final DateTimeFormatter DFY_MD_HMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  public static final DateTimeFormatter DFY_MD_HM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  public static final DateTimeFormatter DFY_MD = DateTimeFormatter.ofPattern("yyyy-MM-dd");

  public MyDateUtil() {
  }

  public static Long getTimeStamp(LocalDateTime localDateTime) {
    return localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
  }

  public static LocalDateTime fromTimeStamp(Long timeStamp) {
    return LocalDateTime.ofEpochSecond(timeStamp, 0, OffsetDateTime.now().getOffset());
  }

  public static Date toDate(LocalDateTime localDateTime) {
    return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
  }

  public static Date toDate(LocalDate localDate) {
    return toDate(localDate.atTime(LocalTime.now(ZoneId.systemDefault())));
  }

  public static LocalDateTime toLocalDateTime(Date date) {
    return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
  }

  public static String localDateTimeFormat(LocalDateTime localDateTime, String patten) {
    DateTimeFormatter df = DateTimeFormatter.ofPattern(patten);
    return df.format(localDateTime);
  }

  public static String localDateFormat(LocalDate localDate, String patten) {
    DateTimeFormatter df = DateTimeFormatter.ofPattern(patten);
    return df.format(localDate);
  }

  public static String localDateTimeFormat(LocalDateTime localDateTime, DateTimeFormatter df) {
    return df.format(localDateTime);
  }

  public static String localDateTimeFormatyMdHms(LocalDateTime localDateTime) {
    return DFY_MD_HMS.format(localDateTime);
  }

  public String localDateTimeFormatyMd(LocalDateTime localDateTime) {
    return DFY_MD.format(localDateTime);
  }

  public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, String pattern) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
    return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
  }

  public static LocalDateTime parseLocalDateTimeFormat(String localDateTime, DateTimeFormatter dateTimeFormatter) {
    return LocalDateTime.from(dateTimeFormatter.parse(localDateTime));
  }

  public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
    return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
  }

  public static LocalDate parseLocalDateFormat(String localDateTime) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    return LocalDate.parse(localDateTime, dateTimeFormatter);
  }

  public static LocalDate parseLocalDateFormat(String localDateTime, String pattern) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
    return LocalDate.parse(localDateTime, dateTimeFormatter);
  }

  public static Long getSecondsNextEarlyMorning() {
    Calendar cal = Calendar.getInstance();
    cal.add(6, 1);
    cal.set(11, 0);
    cal.set(13, 0);
    cal.set(12, 0);
    cal.set(14, 0);
    return cal.getTimeInMillis() - System.currentTimeMillis();
  }

  public static void main(String[] args) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
    LocalDate parse = LocalDate.parse("2021-10-31", dateTimeFormatter);
    System.out.println(parse);
  }
}
